$(function(){
	document.getElementById("loadDiv").style.display = 'block';
	fetchSummary();
	drawWorkTrend();
	drawRateWorkGroupByProject();
	setTimeout(() => {
		document.getElementById("loadDiv").style.display = 'none';
	}, 500)
});

function fetchSummary(){
	var conditionDateStr = conditionDate.format("yyyy-MM-dd");
	var data = {conditionDate : conditionDateStr}
	$.ajax({
        type: "post",
        url: "construction/fetchSummary",
        dataType: "json",
        data : data,
        success: function (data) {
        	$("#statisticDate").html(data[0].statisticDate);
        	$("#totalPeople").html(data[0].totalPeople);
        	$("#totalReturn").html(data[0].totalReturn);
        	$("#totalQuarantine").html(data[0].totalAmountOfquarantine);
        	$("#totalAmountOfWork").html(data[0].totalAmountOfWork);
    	}
    });
}

function drawWorkTrend(){
	var conditionDateStr = conditionDate.format("yyyy-MM-dd");
	var data = {conditionDate : conditionDateStr}
	var myChart = echarts.init(document.getElementById('zhu'));
	
	var dataX = [];
	var dataY1 = [];//累计人数
	var dataY2 = [];//隔离观察人数
	var dataY3 = [];//可返岗人数
	var dataY4 = [];//返岗率
	//Ajax动态改变数据
    $.ajax({
        type: "post",
        url: "construction/fetchWorkTrend",
        data : data,
        dataType: "json",
        success: function (data) {
        	
        	for(var i in data){
        		dataX.push(data[i].statisticDate);
        		dataY1.push(data[i].totalPeople);
        		dataY2.push(data[i].totalQuarantine);
        		dataY3.push(data[i].totalAmountOfWork);
        		dataY4.push((data[i].totalAmountOfWork/data[i].totalPeople*100).toFixed(2));
        	}
        	var option = {
					title: {
				        x: 'center',
				        y: 0,
				        textStyle:{
				            color:'#B4B4B4',
				            fontSize:13,
				            fontWeight:'normal',
				        },
				        
				    },
				    tooltip: {
				        trigger: 'axis',
				    },
				    legend: {
						show:true,
						top: "4%",
						textStyle: {
				            color: '#B4B4B4'
				        },
						data:['总人数','可返岗人数','人员可返岗率']
					},
					grid:{
						left: '12%',  
						right: '12%',
						bottom:'22%'
				    },
        		    xAxis: [
        		        {
        		        	data: dataX,
        		        	axisLine: {
        			            lineStyle: {
        			                color: '#B4B4B4'
        			            }
        			        },
        			        axisLabel:{
        			        	rotate : 45
        			        },
        			        axisTick:{
        			            show:false,
        			        },
        		            
        		        }
        		    ],
        		    yAxis: [
        		    	{
        			        splitLine: {show: false},
        			        axisLine: {
        			            lineStyle: {
        			                color: '#B4B4B4',
        			            }
        			        },
        			        axisLabel:{
        			            formatter:'{value}',
        			        }
    			    	},
    			        {
        			        splitLine: {show: false},
        			        axisLine: {
        			            lineStyle: {
        			                color: '#B4B4B4',
        			            }
        			        },
        			        axisLabel:{
        			            formatter:'{value}%',
        			        },
        			        min : function(value){
            		        	return (value.min-2).toFixed(0);
            		        },
            		        max :100
        			    }
        		    ],
        		    dataZoom: [{
    			        show: true,
    			        height: 20,
    			        startValue: dataX.length-10,
    			        handleStyle:{
    			            color:"#d3dee5",
    			            
    			        },
    		           textStyle:{
    		        	   color:"#fff"
    	        	   },
    		           borderColor:"#90979c"
    			        
    			    }, {
    			        type: "inside",
    			        show: true,
    			        height: 15,
    			        start: 1,
    			        end: 35
    			    }],
        		    series: [
        		        {
        		            name:'总人数',
        		            type:'bar',
        		            barWidth: 10,
        		            itemStyle: {
        		                normal: {
        		                    barBorderRadius: 5,
        		                    color: new echarts.graphic.LinearGradient(
        				                    0, 0, 0, 1,
        				                    [
        				                        {offset: 0, color: '#CCE6F5'},
        				                        {offset: 1, color: '#E3F1E4'}
        				                    ]
        				                )
        		                }
        		            },
        		            yAxisIndex: 0,
        		            data:dataY1
        		        },
        		        {
        		            name:'可返岗人数',
        		            type:'bar',
        		            barWidth: 10,
        		            itemStyle: {
        		            	normal: {
        			                barBorderRadius: 5,
        			                color: new echarts.graphic.LinearGradient(
        				                    0, 0, 0, 1,
        				                    [
        				                        {offset: 0, color: '#4DA2DA'},
        				                        {offset: 1, color: '#00D488'}
        				                    ]
        				                )
        			                
        			            }
        		            },
        		            barGap: '-100%',
        		            yAxisIndex: 0,
        		            data:dataY3
        		        },
        		        {
        		            name:'人员可返岗率',
        		            type:'line',
        		            smooth: true,
        		            showAllSymbol: true,
        		            symbol: 'emptyCircle',
        		            symbolSize: 8,
        		            yAxisIndex: 1,
        		            itemStyle: {
        		                    normal: {
        		                    color:'#FF5E5E'},
        		            },
        		            data:dataY4
        		        }
        		    ]
        		};
        	
        	myChart.setOption(option);
        }
    });
}

function drawRateWorkGroupByProject(){
	var conditionDateStr = conditionDate.format("yyyy-MM-dd");
	var data = {conditionDate : conditionDateStr}
	
	var myChart = echarts.init(document.getElementById('card_one'));
	var dataX = [];
	var dataY1 = [];
	var dataY2 = [];
	var dataY3 = [];
	var dataY4 = [];
	var dataY5 = [];
	var dataY6 = [];
	var dataY7 = [];
	var currentDateArray = [];
	
	//Ajax动态改变数据
    $.ajax({
        type: "post",
        url: "construction/fetchRateWorkGroupByProject",
        dataType: "json",
        data : data,
        success: function (data) {
        	var dataY7totalPeople=0;
        	var dataY7totalAmountOfWork=0;
        	for(var i in data){
        		if(currentDateArray.length == 0){
        			dataY7totalPeople += data[i].totalPeople;
        			dataY7totalAmountOfWork += data[i].totalAmountOfWork;
        			currentDateArray.push(data[i].statisticDate);
        			
        		}else if(currentDateArray.indexOf(data[i].statisticDate)<0){
        			currentDateArray.push(data[i].statisticDate);
        			dataY7.push((dataY7totalAmountOfWork/dataY7totalPeople*100).toFixed(2));
        			
        			dataY7totalPeople=data[i].totalPeople;
                	dataY7totalAmountOfWork=data[i].totalAmountOfWork;
        			
        		}else{
        			dataY7totalPeople += data[i].totalPeople;
        			dataY7totalAmountOfWork += data[i].totalAmountOfWork;
        		}
        		
        		if(i==data.length-1){
        			//最后一条
        			dataY7.push((dataY7totalAmountOfWork/dataY7totalPeople*100).toFixed(2));
        		}
        		
        		
        		if(data[i].projectId==1){
        			dataX.push(data[i].statisticDate);
        			dataY1.push((data[i].totalAmountOfWork/data[i].totalPeople*100).toFixed(2));
        		}
        		if(data[i].projectId==2){
        			dataY2.push((data[i].totalAmountOfWork/data[i].totalPeople*100).toFixed(2));
        		}
        		if(data[i].projectId==3){
        			dataY3.push((data[i].totalAmountOfWork/data[i].totalPeople*100).toFixed(2));
        		}
        		if(data[i].projectId==4){
        			dataY4.push((data[i].totalAmountOfWork/data[i].totalPeople*100).toFixed(2));
        		}
        		if(data[i].projectId==5){
        			dataY5.push((data[i].totalAmountOfWork/data[i].totalPeople*100).toFixed(2));
        		}
        		if(data[i].projectId==6){
        			dataY6.push((data[i].totalAmountOfWork/data[i].totalPeople*100).toFixed(2));
        		}
        	}
        	
        		var option = {
        		    tooltip: {
        		        trigger: 'axis',
        		        formatter:function(param){
	    		        	var tooltipStr = param[0].name+"<br>";
	    		        	for(var p in param){
	    		        		tooltipStr+=param[p].marker+" " + param[p].seriesName+"："+param[p].value+"%<br>";
	    		        	}
							return tooltipStr;
        		        }
        		    },
//        		    legend: {
//        		        data:  ["9号线","10号线二期","13号线","14号线","15号线","18号线","综合"],
//        		        top: '1',
//        				orient: 'horizontal',
//        				x: 'center',
//        				y: 'top',
//        		    },
        		    legend: [
        		    	{
        		            x:'center',
        		            data: ["9号线","10号线二期","13号线","14号线"]
        		        },
        		        {
        		            x:'center',
        		            top:'8%',
        		            data: ["15号线","18号线","综合"]
        		        }
        		    ],
        		    grid: {
        		    	top: '20%',
        		        left: '14%',
        		        right: '5%',
        		        bottom:'22%'
        		    },
        		    xAxis: {
        		        type: 'category',
        		        data: dataX,
        		        axisLabel:{
        		        	rotate : 45
        		        },
        		    },
        		    yAxis: {
        		        type: 'value',
        		        axisLabel: {
    		                formatter: '{value} %'
    		            },
        		        splitLine: {
        		            lineStyle: {
        		                type: 'dashed',
        		                color: '#DDD'
        		            }
        		        },
        		        axisLine: {
        		            show: false,
        		            lineStyle: {
        		                color: "#333"
        		            },
        		        },
        		        nameTextStyle: {
        		            color: "#999"
        		        },
        		        splitArea: {
        		            show: false
        		        },
        		        min : function(value){
        		        	return (value.min-2).toFixed(0);
        		        },
        		        max :100
        		    },
        		    dataZoom: [{
    			        show: true,
    			        height: 20,
    			        startValue: dataX.length-10,
    			        handleStyle:{
    			            color:"#d3dee5",
    			            
    			        },
    		           textStyle:{
    		        	   color:"#fff"
    	        	   },
    		           borderColor:"#90979c"
    			        
    			    }, {
    			        type: "inside",
    			        show: true,
    			        height: 15,
    			        start: 1,
    			        end: 35
    			    }],
        		    series: [{
        		            name: '9号线',
        		            type: 'line',
        		             smooth: true,
        		            data: dataY1,
        		            lineStyle: {
        		                normal: {
        		                    width: 3,
        		                    color: {
        		                        type: 'linear',

        		                        colorStops: [{
        		                            offset: 0,
        		                            color: '#B3DDEE' // 0% 处的颜色
        		                        }, {
        		                            offset: 1,
        		                            color: '#69C5E9' // 100% 处的颜色
        		                        }],
        		                        globalCoord: false // 缺省为 false
        		                    },
        		                }
        		            },
        		            itemStyle: {
        		                normal: {
        		                    color: '#69C5E9',
        		                    borderWidth: 5,
        		                    borderColor: "#69C5E9"
        		                }
        		            },
        		            smooth: true
        		        },
        		        {
        		            name: '10号线二期',
        		            type: 'line',
        		             smooth: true,
        		            data: dataY2,
        		            lineStyle: {
        		                normal: {
        		                    width: 3,
        		                    color: {
        		                        type: 'linear',

        		                        colorStops: [{
        		                                offset: 0,
        		                                color: '#E6CEFF' // 0% 处的颜色
        		                            },
        		                            {
        		                                offset: 1,
        		                                color: '#C3A5E1' // 100% 处的颜色
        		                            }
        		                        ],
        		                        globalCoord: false // 缺省为 false
        		                    },
        		                }
        		            },
        		            itemStyle: {
        		                normal: {
        		                    color: '#C3A5E1',
        		                    borderWidth: 5,
        		                    borderColor: "#C3A5E1"
        		                }
        		            },
        		            smooth: true
        		        },
        		        {
        		            name: '13号线',
        		            type: 'line',
        		             smooth: true,
        		            data: dataY3,
        		            lineStyle: {
        		                normal: {
        		                    width: 3,
        		                    color: {
        		                        type: 'linear',

        		                        colorStops: [{
        		                            offset: 0,
        		                            color: '#FFC9EB' // 0% 处的颜色
        		                        }, {
        		                            offset: 1,
        		                            color: '#F095CE' // 100% 处的颜色
        		                        }],
        		                        globalCoord: false // 缺省为 false
        		                    },
        		                }
        		            },
        		            itemStyle: {
        		                normal: {
        		                    color: '#F095CE',
        		                    borderWidth: 5,
        		                    borderColor: "#F095CE"
        		                }
        		            },
        		            smooth: true
        		        },
        		        {
        		            name: '14号线',
        		             smooth: true,
        		            type: 'line',
        		            data: dataY4,
        		            lineStyle: {
        		                normal: {
        		                    width: 3,
        		                    color: {
        		                        type: 'linear',

        		                        colorStops: [{
        		                            offset: 0,
        		                            color: '#C0BFA4' // 0% 处的颜色
        		                        }, {
        		                            offset: 1,
        		                            color: '#7F7900' // 100% 处的颜色
        		                        }],
        		                        globalCoord: false // 缺省为 false
        		                    },
        		                }
        		            },
        		            itemStyle: {
        		                normal: {
        		                    color: '#7F7900',
        		                    borderWidth: 5,
        		                    borderColor: "#7F7900"
        		                }
        		            },
        		            smooth: true
        		        },
        		        {
        		            name: '15号线',
        		            smooth: true,
        		            type: 'line',
        		            data: dataY5,
        		            lineStyle: {
        		                normal: {
        		                    width: 3,
        		                    color: {
        		                        type: 'linear',

        		                        colorStops: [{
        		                            offset: 0,
        		                            color: '#DFD9CF' // 0% 处的颜色
        		                        }, {
        		                            offset: 1,
        		                            color: '#BCA887' // 100% 处的颜色
        		                        }],
        		                        globalCoord: false // 缺省为 false
        		                    },
        		                }
        		            },
        		            itemStyle: {
        		                normal: {
        		                    color: '#BCA887',
        		                    borderWidth: 5,
        		                    borderColor: "#BCA887"
        		                }
        		            },
        		            smooth: true
        		        },
        		        {
        		            name: '18号线',
        		             smooth: true,
        		            type: 'line',
        		            data: dataY6,
        		            lineStyle: {
        		                normal: {
        		                    width: 3,
        		                    color: {
        		                        type: 'linear',

        		                        colorStops: [{
        		                            offset: 0,
        		                            color: '#FFE4C2' // 0% 处的颜色
        		                        }, {
        		                            offset: 1,
        		                            color: '#DCAE73' // 100% 处的颜色
        		                        }],
        		                        globalCoord: false // 缺省为 false
        		                    },
        		                }
        		            },
        		            itemStyle: {
        		                normal: {
        		                    color: '#DCAE73',
        		                    borderWidth: 5,
        		                    borderColor: "#DCAE73"
        		                }
        		            },
        		            smooth: true
        		        },
        		        {
        		            name: '综合',
        		             smooth: true,
        		            type: 'line',
        		            data: dataY7,
        		            lineStyle: {
        		                normal: {
        		                    width: 3,
        		                    color: {
        		                        type: 'linear',

        		                        colorStops: [{
        		                            offset: 0,
        		                            color: '#FCAAAA' // 0% 处的颜色
        		                        }, {
        		                            offset: 1,
        		                            color: '#EC0000' // 100% 处的颜色
        		                        }],
        		                        globalCoord: false // 缺省为 false
        		                    },
        		                }
        		            },
        		            itemStyle: {
        		                normal: {
        		                    color: '#EC0000',
        		                    borderWidth: 5,
        		                    borderColor: "#EC0000"
        		                }
        		            },
        		            smooth: true
        		        }
        		    ]
        		};
        		myChart.setOption(option);
        }
    });
}
////各线路建设工地人员可返岗率变化趋势图
//$(function(){
//	var myChart = echarts.init(document.getElementById('card_one'));
//	
//	myChart.setOption(option);
//		
//})


